package com.hongding.sealcenter.exception;

import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.exception.NotPermissionException;
import cn.dev33.satoken.exception.NotRoleException;
import com.hongding.sealcenter.enums.GlobeCodeEnum;
import com.hongding.sealcenter.response.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常拦截
 */
@RestControllerAdvice
@Component
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(NotLoginException.class)
    public ResponseEntity NotLoginExceptionHandler(){
        log.error("用户未登录");
        return ResponseUtil.httpError(GlobeCodeEnum.NO_LOGIN.getName());
    }

    @ExceptionHandler(NotPermissionException.class)
    public ResponseEntity NotPermissionExceptionHandler(){
        log.error("用户没有操作权限");
        return ResponseUtil.httpError(GlobeCodeEnum.NO_PERMISSION.getName());
    }

    @ExceptionHandler(NotRoleException.class)
    public ResponseEntity NotRoleExceptionHandler(){
        log.error("用户没有角色权限");
        return ResponseUtil.httpError(GlobeCodeEnum.NO_ROLE.getName());
    }
}
